The code shown for your array named a should work. You have:
NSMutableArray<NSNumber*> *a = @[@(0), @(0), @(0)].mutableCopy;
a[3] = @(1); // works, but why?
a[4] = @(1); // also works
So you have three NSNumbers in an array at index 0, 1, 2.
Then you add another number at index 3, which would be the same thing as doing this:
[a addObject:@(1)];
I could be wrong but I believe the line in the documentation below is wrong:
If index is beyond the end of the array (that is, if index is greater than or equal to the value returned by count), an NSRangeException is raised.
I think it should say:
If index is beyond the end of the array (that is, if index is greater than the value returned by count), an NSRangeException is raised.
The documentation also says:
Replaces the object at the index with the new object, possibly adding the object.
You probably should file a bug. Either the documentation or the code is wrong but I believe it is the documentation.